package d1_stream;

import java.util.*;
import java.util.stream.Stream;

public class StreamTest02 {
    public static void main(String[] args) {
        //目标: 获取Stream流
        //1、获取集合的Stream流: default Stream<E> stream()
        Collection<String> list = new ArrayList<>();
        //往集合中添加元素
        Collections.addAll(list, "陈平安", "宁姚", "姬紫月", "叶凡", "秦牧");

        //获取Stream流
        Stream<String> str1 = list.stream();
        //获取流元素的个数
        System.out.println(str1.count());//5

        //2、获取Map集合的Stream流(可以说这个流只是针对单列集合)
//        Map<String, Integer> map = new HashMap<>();
        HashMap<String, Integer> map = new HashMap<>();
        //a、获取键流
//        Stream<String> keyStream = map.keySet().stream();
        Stream<String> keyStream = map.keySet().stream();
        //b、获取值流
//        Stream<Integer> valueStream = map.values().stream();
        Stream<Integer> valueStream = map.values().stream();

        //获取Entry对象流(键值对流)
        //c、键值对流 --> 获取的是一对键值对
//        Stream<Map.Entry<String, Integer>> entryStream = map.entrySet().stream();
        Stream<Map.Entry<String, Integer>> entryStream = map.entrySet().stream();
        //3、获取数组的Stream
        //创建一个数组
        String[] names = {"陈平安", "宁姚", "姬紫月", "叶凡", "秦牧"};
        //a、使用Arrays提供的方法
        //public static <T> Stream<T> stream(T[] array) //获取当前数组的Stream
        Stream<String> arrayStream = Arrays.stream(names);

        //b、使用Stream类提供的方法
        //public static <T> Stream of(T...values) //获取当前接受数据的Stream流
        Stream<String> arrayStream1 = Stream.of(names);
       /* int a =0;
        Stream.of(a);*/

    }
}
